package cn.tiny.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created on 2019/1/7 18:48
 */
public class DateUtil {
    public static final String YMD ="yyyy-MM-dd";
    public static final String YMDHM = "yyyy-MM-dd HH:mm";
    public static final String YMDHMS = "yyyy-MM-dd HH:mm:ss";

    private static String getDatePattern() {
        return YMDHMS;
    }

    /**
     * Created on 2019/1/7 18:51
     */
    public static String format(Date date) {
        return format(date, getDatePattern());
    }

    /**
     * Created on 2019/1/7 18:50
     */
    public static String format(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        return df.format(date);
    }
}
